
#pragma once

#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>

#include <iostream>

using namespace cv;

namespace course_06_color_detection
{

    void color_detection(std::string path)
    {

        int hmin = 0, smin = 110, vmin = 153;
        int hmax = 19, smax = 240, vmax = 255;
        Mat imageHSV, mask;

        Mat image = imread(path);

        cvtColor(image, imageHSV, COLOR_BGR2HSV);

        namedWindow("trackbars",(640,200));
        createTrackbar("hmin","trackbars",&hmin,150);
        createTrackbar("smin","trackbars",&smin,150);
        createTrackbar("vmin","trackbars",&vmin,255);

        createTrackbar("hmax","trackbars",&hmax,255);
        createTrackbar("smax","trackbars",&smax,255);
        createTrackbar("vmax","trackbars",&vmax,255);

        while (true)
        {
            //根据HSV的范围创建遮罩
            Scalar lower(hmin, smin, vmin);
            Scalar upper(hmax, smax, vmax);
            inRange(imageHSV, lower, upper, mask);

            imshow("IMAGE", image);
            imshow("IMAGE-HSV", imageHSV);
            imshow("IMAGE-mask", mask);

            waitKey(1);
        }
    }
}